import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)


const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}

const routes = [{
		path: '/nav',
		component: () => import('@/views/Site-Nav/nav.vue'),
	},
	{
		path: '/login/handlerqqlogin',
		component: () => import('@/views/Login/handleQQLogin.vue'),
	},
	{
		path: "/",
		component: () => import('@/views/Index/index.vue'),
		redirect: '/home',
		children: [{
				path: '/home',
				component: () => import("@/views/Home/home.vue")
			},
			{
				path: '/404',
				component: () => import("@/views/404.vue")
			}, {
				path: '/note',
				name: 'Note',
				component: () => import("@/views/Note/note.vue")
			}, {
				path: '/blog-detail/:id',
				name: 'blog-detail',
				component: () => import("@/views/Blog-Detail/detail.vue")
			},
			{
				path: '/dz',
				name: 'dz',
				component: () => import("@/views/test/dz.vue")
			}
		]
	}
]

const router = new VueRouter({
	mode: 'history',
	base: process.env.BASE_URL,
	routes
})
router.beforeEach((to, from, next) => {
	if (to.matched.length !== 0) {
		next()
	} else {
		next({
			path: '/404?path=' + to.path
		})
	}
});

export default router
